package com.easywan.web.controller.system;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.easywan.core.HTMLModelAndView;
import com.easywan.core.JSPModelAndView;
import com.easywan.service.UsersService;
import com.easywan.util.Utils;
import com.easywan.vo.Users;
/**
 * @author T
 * 登录界面
 */
//@Controller
public class LoginController {
	private Logger logger = Logger.getLogger(LoginController.class);
	@Autowired
	private UsersService userService;
	/**
	 * 登录页面
	 * @param req
	 * @param res
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("login")
	public ModelAndView login_html(HttpServletRequest req,HttpServletResponse res,ModelMap modelMap){
		return new JSPModelAndView("system/login",modelMap);
	}
	@RequestMapping("login_chk")
	public void login(HttpServletRequest req,HttpServletResponse res,ModelMap modelMap,Users users,HttpSession session){
		Users userLogin = userService.login(users);
		if(userLogin != null){
			if(userLogin.getEmailvif()){
				Utils.sendMsg(res, "1");
				session.setAttribute("users", userLogin);
			}else{
				Utils.sendMsg(res, "-1");
				session.setAttribute("users", userLogin);
			}
		}else{
			Utils.sendMsg(res, "0");
		}
	}
	
	
	@RequestMapping("admin/login")
	public ModelAndView login_html_admin(){
		return new HTMLModelAndView("admin/login/login");
	}
}
